import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex);


const store = new Vuex.Store({
  state: {
    tabsId: localStorage.getItem('tabsCard')?localStorage.getItem('tabsCard'):0, //tabs标签当前索引
    tabsList: localStorage.getItem('tabsArr')?JSON.parse(localStorage.getItem('tabsArr')):[{
      m_id: 0,
      m_name: '首页',
      route: 'Home',
      noClose: true
    }], //tabs标签列表
    menuGroup:[],//菜单列表
  },
  mutations: {
    editTabsId(state, value) {
      state.tabsId = value;
      localStorage.setItem('tabsCard',state.tabsId)
    },
    editTabsList(state, value) {
      console.log(value)
      if(Array.isArray(value)){
        state.tabsList = value;
      }else{
        let isHaveTabs=state.tabsList.findIndex(item=>{return item.m_id==value.m_id})==-1
        if(isHaveTabs){
          state.tabsList.push(value)
        }
      }
      localStorage.setItem('tabsArr',JSON.stringify(state.tabsList))
    },
    editmenuGroup(state, value) {
      state.menuGroup = value;
    },
    // 重置vuex本地储存状态
    RESET_STATE(state) {
      // 重置所有状态到初始状态
      state.tabsId= localStorage.getItem('tabsCard')?localStorage.getItem('tabsCard'):0, //tabs标签当前索引
      state.tabsList= localStorage.getItem('tabsArr')?JSON.parse(localStorage.getItem('tabsArr')):[{
        m_id: 0,
        m_name: '首页',
        route: 'Home',
        noClose: true
      }], //tabs标签列表
      state.menuGroup=[]//菜单列表
    }
  },
  actions: {

  }
});

export default store;